<?php
global $General, $Cart, $wpdb, $current_user, $country_db_table_name, $state_db_table_name;
//$orderNumber; // order number
$paymentOpts = $General->get_payment_optins($_REQUEST['paymentmethod']);
$merchantid = $paymentOpts['merchantid'];
$returnUrl = $paymentOpts['returnUrl'];
$cancel_return = $paymentOpts['cancel_return'];
$notify_url = $paymentOpts['notify_url'];
$currency_code = $General->get_currency_code();
$cartInfo = $Cart->getcartInfo();
$itemArr = array();
for($i=0;$i<count($cartInfo);$i++)
{
	$product_att = preg_replace('/([(])([+-])([0-9]*)([)])/','',$cartInfo[$i]['product_att']);
	$itemstr = '';
	$itemstr .= $cartInfo[$i]['product_qty'].' X '.$cartInfo[$i]['product_name'];
	if($product_att)
	{
		$itemstr .="($product_att)";
	}
	$itemArr[] = $itemstr;
	
}
$item_name = implode(', ',$itemArr);
$amount = $General->get_payable_amount();
$payable_amt = $General->get_payable_amount($_REQUEST['shippingmethod']);


$user_id = $current_user->data->ID;
$user_address_info = $current_user->data->user_address_info;
$user_email = $userInfo['user_email'];
$first_name = get_usermeta($user_id, 'first_name');
$last_name = get_usermeta($user_id, 'last_name');
$user_add1 = $user_address_info['user_add1'];
$user_add2 = $user_address_info['user_add2'];
$user_city = $user_address_info['user_city'];
$user_state = $user_address_info['user_state'];
$user_country = $user_address_info['user_country'];
$phone = $user_address_info['phone'];
$user_postalcode = $user_address_info['user_postalcode'];

if($user_country)
{
	$user_country_ID = $wpdb->get_var("select country  from $country_db_table_name where title like \"$user_country\"");
}
if($user_state)
{
	$user_state_ID = $wpdb->get_var("select state from $state_db_table_name where title like \"$user_state\"");
}
?>
<form name="frm_payment_method" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<?php /*?><form name="frm_payment_method" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"><?php */?>
<input type="hidden" value="<?php echo $payable_amt;?>" name="amount"/>
<input type="hidden" value="<?php echo $returnUrl;?>&oid=<?php echo $orderNumber;?>" name="return"/>
<input type="hidden" value="<?php echo $cancel_return;?>&oid=<?php echo $orderNumber;?>" name="cancel_return"/>
<input type="hidden" value="<?php echo $notify_url;?>" name="notify_url"/>
<input type="hidden" value="_xclick" name="cmd"/>
<input type="hidden" value="<?php echo $item_name;?>" name="item_name"/>
<input type="hidden" value="<?php echo $merchantid;?>" name="business"/>
<input type="hidden" value="<?php echo $currency_code;?>" name="currency_code"/>
<input type="hidden" value="<?php echo $orderNumber;?>" name="custom" />
<input type="hidden" name="H_PhoneNumber" value="<?php echo $phone;?>">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="2">

<input type="hidden" name="address1" value="<?php echo $user_add1;?>">
<input type="hidden" name="address2" value="<?php echo $user_add2;?>">
<input type="hidden" name="city" value="<?php echo $user_city;?>">
<input type="hidden" name="zip" value="<?php echo $user_postalcode;?>">
<input type="hidden" name="state" value="<?php echo $user_state_ID;?>">
<input type="hidden" name="country" value="<?php echo $user_country_ID;?>">
<input type="hidden" name="email" value="<?php echo $user_email;?>">
<input type="hidden" name="first_name" value="<?php echo $first_name;?>">
<input type="hidden" name="last_name" value="<?php echo $last_name;?>">

</form>

<div id="wrapper" class="container_16" >
		<div class="clearfix container_message">
            	<h1 class="processing_message_head">Processing for <?php echo $_REQUEST['paymentmethod'];?>, Please wait ....</h1>
         </div>
</div>
<script>
setTimeout("document.frm_payment_method.submit()",100); 
</script> 